package icu.yougan.youganblogbackend.controller;

import icu.yougan.youganblogbackend.common.Result;
import icu.yougan.youganblogbackend.model.Article;
import icu.yougan.youganblogbackend.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/list")
    public Result<List<Article>> list() {
        return articleService.list();
    }

    @GetMapping("/{id}")
    public Result<Article> getById(@PathVariable Integer id) {
        return articleService.getById(id);
    }

    @GetMapping("/category/{categoryId}")
    public Result<List<Article>> getByCategoryId(@PathVariable Integer categoryId) {
        return articleService.getByCategoryId(categoryId);
    }

    @PostMapping
    public Result<Article> add(@RequestBody Article article) {
        return articleService.add(article);
    }

    @PutMapping
    public Result<Article> update(@RequestBody Article article) {
        return articleService.update(article);
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Integer id) {
        return articleService.delete(id);
    }
} 